package com.xx.controller;

import com.xx.pojo.Orders;
import com.xx.pojo.User;
import com.xx.pojo.UserVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Date;

@Controller
public class MyController {
    // 绑定默认数据类型
    @RequestMapping("/selectUser")
    public String selectUser(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
        String id = request.getParameter("id");
        System.out.println("id:" + id);
        return "success";
    }

    // 绑定简单数据类型
    @RequestMapping("/selectUser2")
    public String selectUser2(int id) {
        System.out.println("id:" + id);
        return "success";
    }

    // 绑定pojo数据类型
    @RequestMapping("/register")
    public String register(User user) {
        System.out.println(user);
        return "success";
    }

    // 绑定pojo封装类型
    @RequestMapping("/findOrders")
    public String findOrders(Orders orders) {
        System.out.println(orders);
        return "success";
    }

    // 绑定自定义类型
    @RequestMapping("/converter")
    public String converter(Date date) {
        System.out.println(date);
        return "success";
    }

    // 绑定自定义类型
    @RequestMapping("/formatter")
    public String formatter(Date date) {
        System.out.println(date);
        return "success";
    }

    // 绑定数组类型
    @RequestMapping("/array")
    public String array(int[] ids) {
        System.out.println(Arrays.toString(ids));
        return "success";
    }

    // 绑定集合类型
    @RequestMapping("/list")
    public String list(UserVO userVO) {
        for (User user : userVO.getUsers()) {
            System.out.println(user);
        }
        return "success";
    }

}
